﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace AsteroidWar
{
    class Nebula
    {
        Texture2D texture;
        Rectangle initialFrame;
        private List<Sprite> nebulaSprites = new List<Sprite>();
        private Vector2 velocity;

        //Padding between two nebulas on the texture
        private int padding = 0;

        private VerticalBackGround verticalBackGround;

        public Nebula(
            Texture2D texture,
            Rectangle initialFrame,
            int FrameRows,
            int FrameColumns,
            Vector2 velocity,
            Viewport viewPort)
        {
            this.texture = texture;
            this.initialFrame = initialFrame;
            this.velocity = velocity;
            
            //Load all nebulas into list Sprite
            for (int x = 0; x < FrameColumns; x++)
                for (int y = 0; y < FrameRows; y++)
                {
                    Sprite nebula = new Sprite(Vector2.Zero, texture, new Rectangle(
                        initialFrame.X + initialFrame.Width * y + padding * 2 * y,
                        initialFrame.Y + initialFrame.Height * x,
                        initialFrame.Width,
                        initialFrame.Height),
                        velocity);
                    nebulaSprites.Add(nebula);
                }

            //Add new effect scrolling background images
            verticalBackGround = new VerticalBackGround(viewPort, nebulaSprites);
            verticalBackGround.adjustBackgroundLocation();
        }

        public void Update(GameTime gameTime)
        {           
            verticalBackGround.Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            verticalBackGround.Draw(spriteBatch);
        }
    }
}
